F1='DLV_PHAR'
F11='DLVPHADO'
sele 1
SET EXCLU OFF
USE &DR&F1
if net_use('&dr&f1',.t.,'1',10)
   INDEX ON COMP_CODE+delv_order TO &DR&F11
endif
unlock
F1='DLV_PHAR'
F2='DLV_TEMP'
SELE 1
SET EXCLU OFF
USE &DR&F1 INDEX &DR&F11
DO WHILE .T.
   DO ADDRDOR1
   @ 8, 5 SAY "MODIFY"
   COMPCOD = SPACE(4)
   set colo to bg+/b,w+/n
   @ 7,1 clear to 23,78
   CNT=0
   KODE=SPACE(4)
   kunci=space(4)
   do boxe with 11,3,'Enter Initial of Client Code : ','KUNCI','N','BG','W+','N',4,.T.,.T.
   if lastkey()=27
      set colo to bg+/b,w+/n
      return
   endif

   do getcompc
   if lastkey()=27
      return
   endif
   SET COLO TO BG+/B,W+/N
   @ 7,1 CLEAR TO 23,78
   SET INDE TO &DR&F11
   SEEK COMPCOD
   IF EOF()
      @ 12, 48  SAY "THIS CODE DOES NOT CORRESPOND"
      @ 13, 48  SAY " >>> TO A LISTED COMPANY <<<<"
      @ 14, 48  SAY " >>> PLEASE ENTER AGAIN ! <<<"
      STORE 0 TO MX
      DO WHILE MX=0
         MX=INKEY()
      ENDDO
      DO CASE
         CASE MX=13
          LOOP
      ENDCASE
      LOOP
   ELSE
      NOR=RECNO()
      EXIT
   ENDIF
ENDDO

COMPNAME=CLIENT
@ 10,3 SAY 'CLIENT NAME : '+COMPNAME

CNT=0
SELE 1
GOTO NOR
DO WHILE .NOT. EOF()
   IF COMP_CODE<>COMPCOD
      SKIP
      LOOP
   ENDIF
   IF DELV_PRINT
      SKIP
      LOOP
   ENDIF
   CNT=CNT+1
   NUMDO=delv_order
   DO WHILE delv_order=NUMDO .AND. .NOT. EOF()
      SKIP
   ENDDO
   SELE 1
ENDDO
IF CNT=0
   SET EXCLU OFF
   CLOSE DATA
   CLOSE INDEX
   RETURN
ENDIF
DECLARE FIL1[CNT]
DECLARE FIL2[CNT]
CR=0
SELE 1
GOTO NOR
DO WHILE .NOT. EOF()
   IF COMP_CODE<>COMPCOD
      SKIP
      LOOP
   ENDIF
   IF DELV_PRINT
      SKIP
      LOOP
   ENDIF
   CR=CR+1
   FIL1[CR]=SUBSTR(DELV_ORDER,7,4)+'     '+DTOC(DATE_DELV)+'   '+PO_NUMB_CL
   FIL2[CR]=DELV_ORDER
   NUMDO=delv_order
   DO WHILE delv_order=NUMDO .AND. .NOT. EOF()
      SKIP
   ENDDO
   SELE 1
ENDDO
TOTDO=0
DO WHILE .T.
   @ 11,  3  TO 23, 47    DOUBLE
   @ 12, 5 SAY 'D.O. #   DATE       P.O. #'
   @ 13, 4 TO 13,46
   inkey()
   cari=achoice(14,5,22,46,fil1)
   mix=lastkey()
   DO CASE
      CASE MIX=13
        DONUM=FIL2[CARI]
        EXIT
      CASE MIX=27
        SET EXCLU OFF
        CLOSE DATA
        CLOSE INDEX
        RETURN
   ENDCASE
ENDDO

SELE 2
USE
IF NET_USE("&DR&F2",.T.,'2',10)
   ZAP
ENDIF
SET EXCLU OFF
SELE 1
SEEK COMPCOD+DONUM
IF .NOT. EOF()
   CLI=CLIENT
   DELV=delv_order
   TGL=DATE_DELV
   DO WHILE delv_order=DONUM .AND. .NOT. EOF()
      NOREC=RECNO()
      AREA='1'
      SELE 2
      IF FIL_LOCK(0)
         APPEND BLANK
      ENDIF
      IF REC_LOCK(0)
         REPL B->CLIENT WITH A->CLIENT
         REPL B->COMP_CODE WITH A->COMP_CODE
         REPL B->PHAR_CODE  WITH A->PHAR_CODE
         REPL B->TRANS_PRIC WITH A->TRANS_PRIC
         REPL B->DATE_DELV   WITH A->DATE_DELV
         REPL B->QANT_DELV   WITH A->QANT_DELV
         REPL B->VAL_DELV   WITH A->VAL_DELV
         REPL B->PHAR_NAME WITH A->PHAR_NAME
         REPL B->PHAR_TYPE WITH A->PHAR_TYPE
         REPL B->PHAR_QANT WITH A->PHAR_QANT
         REPL B->PHAR_UNIT WITH A->PHAR_UNIT
         REPL B->BUY_UNIT WITH A->BUY_UNIT
         REPL B->NO_REC WITH NOREC
         REPL B->DATA_AREA WITH A->DATA_AREA
      ENDIF
      UNLOCK
      SELE 1
      SKIP
   ENDDO
ENDIF
TOTDO=0
LNJ=.T.
DO WHILE LNJ
   TOTDO=0
   SELE 2
   COUNT TO CNT
   DECLARE NOREC[CNT]
   DECLARE FILD[CNT]
   GOTO TOP
   CR=0
   DO WHILE .NOT. EOF()
      CR=CR+1
      NOREC[CR]=RECNO()
      CODE=PHAR_CODE
      NAME=PHAR_NAME
      TYPE=PHAR_TYPE
      FILD[CR]=PHAR_CODE+' '+CHR(179)+' '+NAME+' '+CHR(179)+' '+TYPE+' '+;
      CHR(179)+' '+STR(QANT_DELV,8)+' '+chr(179)+' '+STR(VAL_DELV,8)
      TOTDO=TOTDO+VAL_DELV
      SKIP
   ENDDO
   DO WHILE .T.
      @  7,3 CLEA TO 9,29
      @  8,  5  SAY "EDIT DELIVERY ORDER   "
      @  7,  3  TO  9, 27  DOUBLE
      @ 10,3 CLEA TO 21,76
      @ 7, 30 CLEAR TO 9,76
      @ 7, 30 SAY "CLIENT :"
      @ 9 ,30 SAY "D.O. # :"
      @ 7 ,39 SAY CLI
      @ 9 ,39 SAY donum
      @ 23,  2  SAY "PREVIOUS SCREEN ->> Pg Up     NEXT SCREEN ->> Pg Dn     PREVIOUS MENU ->> Esc"
      @ 22,  0  TO 24, 28
      @ 22, 30  TO 24, 54
      @ 22, 56  TO 24, 79
      @ 11,  5  SAY "CODE    DESCRIPTION            TYPE           QUANTITY   COST"
      @ 10,3 TO 20,71
      BR=11
      DO WHILE BR<19
         BR=BR+1
         @ BR,11 SAY CHR(179)
         @ BR,34 SAY CHR(179)
         @ BR,49 SAY CHR(179)
         @ BR,60 SAY CHR(179)
      ENDDO
      @ 12,3 TO 12,71
      @ 12,3  SAY CHR(195)
      @ 12,11 SAY CHR(197)
      @ 12,34 SAY CHR(197)
      @ 12,49 SAY CHR(197)
      @ 12,60 SAY CHR(197)
      @ 12,71 SAY CHR(180)
      @ 21,49 SAY "TOTAL D.O. : "+STR(TOTDO,8)
      inkey()
      cari=achoice(13,5,19,69,fild)
      mix=lastkey()
      DO CASE
         CASE MIX=13
              NR=NOREC[CARI]
              GOTO NR
              CLEA
              DO ADDRESSA
              @  8,  5  SAY "EDIT DELIVERY ORDER"
              @  7,  3  TO  9, 28  DOUBLE
              @ 7, 30 SAY "CLIENT :"
              @ 9 ,30 SAY "D.O. # :"
              @ 7 ,39 SAY CLI
              @ 9 ,39 SAY donum
              @ 11,  3  TO 15, 76
              DCODE     = PHAR_CODE
              PHARNAME  = PHAR_NAME
              PHARTYPE  = PHAR_TYPE
              PHARQANT  = PHAR_QANT
              PHARUNIT  = PHAR_UNIT
              PHARBUNIT = BUY_UNIT
              @ 12,  6  SAY "     CODE :"
              @ 12, 18  SAY PHAR_CODE pict "@!"
              @ 13,  5  SAY "NAME :"
              @ 13, 12  SAY PHARNAME
              @ 13, 33  SAY "TYPE :"
              @ 13, 40  SAY PHARTYPE
              @ 13, 51  SAY "CONTENT :"
              @ 13, 61  SAY PHARQANT
              @ 13, 69  SAY PHARUNIT
              @ 14,  5  SAY "BUYING UNIT :"
              @ 14, 19  SAY PHARBUNIT
              @ 14, 30  SAY "QUANTITY IN D. O. :"
              @ 14, 50  SAY QANT_DELV
              @ 14, 62  SAY PHARBUNIT
              @ 16,3 TO 18,26 DOUBLE
              @ 17,5 SAY 'CORRECTION (Y/N) :'
              CORREC='Y'
              DO TANYA WITH 17,24,'YN',CORREC
              IF CORREC='Y'
                 MQANT=QANT_DELV
                 VALOLD=VAL_DELV
                 QANOLD=QANT_DELV
                 NOREC=NO_REC
                 AREA=DATA_AREA
                 QANT=0
                 @ 16,30 TO  18,65 DOUBLE
                 @ 17,32 SAY 'CORRECT QUANTITY :'
                 @ 17,51 GET QANT
                 READ
                 do case
                    case substr(phar_code,2,1)='0' .or. substr (phar_code,2,1)='1'.OR. substr(phar_code,2,1)='4' .or. substr (phar_code,2,1)='5' .OR. SUBSTR(PHAR_CODE,2,1)='8'
                       F3='DRUGS'
                    case substr(phar_code,2,1)='2' .or. substr (phar_code,2,1)='3'.OR. substr(phar_code,2,1)='6' .or. substr (phar_code,2,1)='7' .OR. SUBSTR(PHAR_CODE,2,1)='9'
                       F3='DISPOS'
                 ENDCASE
                 SET EXCLU OFF
                 SELE 3
                 USE &DR&F3 INDEX &DR&F3
                 SEEK DCODE
                 TRANSPRIC=TRANS_PRIC
                 SELE 2
                 IF QANOLD = 0
                    VR = QANT * TRANSPRIC
                 ELSE
                    if valold=0
                       vr=qant*transpric
                    else
                       VR=VALOLD*(QANT/QANOLD)
                    endif
                 ENDIF
                 DIFF=VR-VALOLD
*                 @ 19, 3  TO 21,32
*                 @ 20, 5  SAY "COST DIFFERENCE : "
*                 @ 20,23 SAY STR(DIFF,8)
                 NOREC=NO_REC
                 @ 21,40 TO 23,78
                 @ 22,42 SAY "Confirm -->> Enter   Cancel -->> F4"
                 DO WHILE .T.
                    STORE 0 TO MX
                    DO WHILE MX=0
                       MX=INKEY()
                    ENDDO
                    DO CASE
                       CASE MX=13
                        @ 21,40 CLEA TO 23,78
                        SELE 1
                        GOTO NOREC
                        IF REC_LOCK(0)
                           REPL QANT_DELV WITH QANT
                           REPL VAL_DELV WITH VR
                        ENDIF
                        UNLOCK
                        SELE 2
                        IF REC_LOCK(0)
                           REPL QANT_DELV WITH QANT
                           REPL VAL_DELV  WITH VR
                        ENDIF
                        UNLOCK
                        SELE 3
                        IF REC_LOCK(0)
*                           REPL ST_ACT_TOT WITH ST_ACT_TOT+MQANT-QANT
                           REPL ST_ALLOCAT WITH ST_ALLOCAT-MQANT+QANT
*                           REPL ST_ACT_BUY WITH INT(ST_ACT_TOT/BUY_SELL_R)
*                           REPL ST_ACT_SEL WITH ST_ACT_TOT-(ST_ACT_BUY*BUY_SELL_R)
                        ENDIF
                        UNLOCK
                        EXIT
                     CASE MX=-3
                        @ 16, 1 CLEA TO 23,78
                        EXIT
                     OTHER
                        LOOP
                  ENDCASE
                  LOOP
                 ENDDO
                 LNJ=.T.
                 EXIT
              ELSE
                 LOOP
              ENDIF
         CASE MIX=27
              LNJ=.F.
              CLOSE DATA
              CLOSE INDEX
              RETURN
      ENDCASE
   ENDDO
ENDDO
